import { redirectTo,setStorageSync, getStorageSync, removeStorageSync } from "@tarojs/taro";

const TOKEN_KEY = 'auth-token';
const INFO_KEY = 'auth-info';

export const getToken = () =>{
    return getStorageSync(TOKEN_KEY);   
}

export const getUserInfo = () =>{
    return getStorageSync<API.UserInfo>(INFO_KEY);
}

export const setToken = (token: string) =>{
    setStorageSync(TOKEN_KEY, token);
}
export const setUserInfo = (info: API.UserInfo) =>{
    setStorageSync(INFO_KEY, info);
}
export const removeToken = () =>{
    removeStorageSync(TOKEN_KEY);
}
export const removeUserInfo = () =>{
    removeStorageSync(INFO_KEY);
}

export const isMeById = (id:string) =>{
    return getUserInfo().id=== id
}


export const loginOut = () =>{
    removeToken()
    removeUserInfo()
    // 跳转到登录页
    redirectTo({url:'/loginAndRegister/login/index'})
}